#include "Tile.h"

#define TILE_WIDTH 64
#define TILE_HEIGHT 32

CTile::CTile() :
m_XCenterPos(NULL),
m_YCenterPos(NULL),
m_IconName(""),
m_MonsterID(NULL),
m_NpcID(NULL),
m_TreasureId(NULL),
m_Wall(FALSE)
{

}

CTile::CTile( UINT XPos, UINT YPos, std::string IconName )
{
    m_XCenterPos = XPos;
    m_YCenterPos = YPos;
    m_IconName = IconName;
    m_MonsterID = NULL;
    m_NpcID = NULL;
    m_TreasureId = NULL;
    m_Wall = FALSE;
}

void CTile::Writer( FILE* pFile )
{
    int _DWNum = m_IconName.length();

    fwrite(&m_XCenterPos, sizeof(m_XCenterPos), 1, pFile);
    fwrite(&m_YCenterPos, sizeof(m_YCenterPos), 1, pFile);
    fwrite(&_DWNum, sizeof(_DWNum), 1, pFile);
    fwrite(m_IconName.c_str(), _DWNum, 1, pFile);
    fwrite(&m_MonsterID, sizeof(m_MonsterID), 1, pFile);
    fwrite(&m_NpcID, sizeof(m_NpcID), 1, pFile);
    fwrite(&m_TreasureId, sizeof(m_TreasureId), 1, pFile);
    fwrite(&m_Wall, sizeof(m_Wall), 1, pFile);
}

void CTile::Reader( FILE* pFile )
{
    int _DWNum = 0;
    char _Buf[256];

    fread(&m_XCenterPos, sizeof(m_XCenterPos), 1, pFile);
    fread(&m_YCenterPos, sizeof(m_YCenterPos), 1, pFile);
    fread(&_DWNum, sizeof(_DWNum), 1, pFile);
    fread(_Buf, _DWNum, 1, pFile);

    _Buf[_DWNum] = 0;
    m_IconName = _Buf;

    fread(&m_MonsterID, sizeof(m_MonsterID), 1, pFile);
    fread(&m_NpcID, sizeof(m_NpcID), 1, pFile);
    fread(&m_TreasureId, sizeof(m_TreasureId), 1, pFile);
    fread(&m_Wall, sizeof(m_Wall), 1, pFile);
}
